package nccloud.web.hrppl.pjapplication;

import java.util.Map;

import nc.bs.client.util.ClientUtils;
import nc.bs.dao.BaseDAO;
import nc.itf.hrppl.pjapplication.IQueryPJApplVOService;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.vo.pub.BusinessException;
import nccloud.framework.core.exception.ExceptionUtils;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.action.itf.ICommonAction;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.json.JsonFactory;

public class QueryFourCGProjectAction implements ICommonAction {

	@SuppressWarnings("rawtypes")
	@Override
	public Object doAction(IRequest request) {
		try {
			String json = request.read();
			Map valMap = JsonFactory.create().fromJson(json, Map.class);
			Object fourpro = valMap.get("fourpro");
//			IQueryPJApplVOService service = ServiceLocator.find(nc.itf.hrppl.pjapplication.IQueryPJApplVOService.class);
//			return service.queryFourCGproject(fourpro);
			return ClientUtils.queryFourCGproject(fourpro);
		} catch (BusinessException e) {
			ExceptionUtils.wrapException(e);
			return null;
		}
	}

	public Integer queryPJApplVOLevelByPK(Object pk_pjappl) throws BusinessException {
		Integer level = 1;
		if(pk_pjappl == null) return level;
		String sql = this.builderHVOSQL(pk_pjappl);
		Object obj = new BaseDAO().executeQuery(sql, new ColumnProcessor());
		if(obj != null) {
			level += Integer.valueOf(obj.toString());
		}
		return level;
	}
	/**
	  * 构建项目级次查询
	 * @param pk_pjappl
	 * @return
	 * @throws BusinessException
	 */
	private String builderHVOSQL(Object pk_pjappl) throws BusinessException{
        return " select def1 from bd_project where dr = 0 and pk_project = '" + pk_pjappl + "' ";
	}
}
